﻿using Logistics.Commn;
using Logistics.Track;
using Microsoft.AspNetCore.Mvc;
using System;
using System.IO;

namespace Logistics.Web.Controllers
{
    public class CargoownerTrackController : Controller
    {
        private readonly ICargoownerTrackAppService _cargoownertrack;
        private readonly ICarryTrackAppService _carrytrack;
        public CargoownerTrackController(ICargoownerTrackAppService cargoownertrack, ICarryTrackAppService carrytrack)
        {
            _cargoownertrack = cargoownertrack;
            _carrytrack = carrytrack;
        }
        public IActionResult Index()
        {
            return View();
        }
        public IActionResult GetList(int page = 1, int limit = 3, string Title = "", string Time = "")
        {
            var CargoownerTrackSearchDto = new CargoownerTrackSearchDto
            {
                SkipCount = (page - 1) * limit,
                MaxResultCount = limit,
                Sorting = "Id desc",
                Title = Title,
                Time = Time,
            };
            var result = _cargoownertrack.GetDapperCargoownerTracks(CargoownerTrackSearchDto).Result;
            var count = result.TotalCount;
            return Ok(new { data = result.Items, count=count, code = "0", msg = "" });
        }
        public IActionResult TrackLine(int Id = 1)
        {
            ViewBag.Id = Id;
            return View();
        }
        public IActionResult GetLine(int Id = 3)
        {
            var list = _carrytrack.GetLineById(Id).Result;
            return Ok(list);
        }
        public IActionResult Update(int Id,int Conditions)
        {
            string Condition = "";
            if (Conditions ==1)
            {
                Condition = "运输中";
            }
            else if(Conditions ==2)
            {
                Condition = "已完成";
            }
            int result= _cargoownertrack.UpdateCargoownerTrack(Id, Condition).Result;
            return Ok(result);
        }
    }
}
